package d5_stream;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Stream;

public class t2 {
    public static void main(String[] args) {
        List<Double> lt = new ArrayList<Double>();
        Collections.addAll(lt,17.2,88.1,45.1,23.7,66.9,44.1);
        lt.stream().filter(s->s>=60).sorted().forEach(System.out::println);//大于等于60 且 升序排序

        List<Student> students =new ArrayList<>();
        Student s1 = new Student("文档",21,177.1);
        Student s7 = new Student("文档",21,177.1);
        Student s2 = new Student("定位",23,184.2);
        Student s3 = new Student("找出",25,151.1);
        Student s4 = new Student("大的",24,162.2);
        Student s5 = new Student("框架",45,148.9);
        Student s6 = new Student("离开",18,169.1);
        Collections.addAll(students, s1,s2,s3,s4,s5,s6,s7);

        students.stream().filter(s->s.getAge()>=23&&s.getAge()<=30).
                sorted((o1,o2)->o2.getAge()-o1.getAge()).//comparator比较器对象
                forEach(System.out::println);


        System.out.println("--------------------------------------------------------------------------------");
        students.stream().sorted(((o1, o2) -> Double.compare(o2.getHeight(), o1.getHeight()))).//double compare方法比较double类型
                limit(3).forEach(System.out::println);//limit取前几



          System.out.println("--------------------------------------------------------------------------------");
//        students.stream().sorted(((o1, o2) -> Double.compare(o1.getHeight(), o2.getHeight()))).//double compare方法比较double类型
//                limit(2).forEach(System.out::println);

        students.stream().sorted(((o1, o2) -> Double.compare(o2.getHeight(), o1.getHeight()))).//double compare方法比较double类型
               skip(students.size()-2).forEach(System.out::println);//skip跳过从第一个开始到第几个

        System.out.println("--------------------------------------------------------------------------------");
        students.stream().filter(s->s.getHeight()>168).map(s->s.getName())
                .distinct().forEach(System.out::println);//去重复记得在类里改写equal和hashCode

        students.stream().filter(s->s.getHeight()>168)
                .distinct().forEach(System.out::println);//去重复

        Stream<String> st1 =Stream.of("发顺丰","大大");
        Stream<String> st2 =Stream.of("发顺丰2","大大2","框架");
        Stream<String> ast =Stream.concat(st1,st2);//合并多数组
        ast.forEach(System.out::println);
    }
}
